package com.example.myapplication.chap02;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class First extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_02_first);
        Button bt = findViewById(R.id.button2);

        bt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        Intent intent = new Intent(this,Second.class);
        Bundle b = new Bundle();
        EditText ed = findViewById(R.id.ed_first);
        String str = ed.getText().toString();
        b.putString("cake",str);
        intent.putExtras(b);
       // startActivity(intent);
        startActivityForResult(intent,2000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 2000){
            if(resultCode == 3000){
                String s = data.getStringExtra("re");
                Log.e("onActivityResult",s);
            }
        }
    }
}
